package com.kaishengit.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.gson.Gson;
import com.kaishengit.entity.Employee;
import com.kaishengit.service.ContactnoteService;
import com.kaishengit.util.StringUtil;

public class ContactnoteRelease extends HttpServlet {

	private static final long serialVersionUID = 1L;
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		Employee e = (Employee) session.getAttribute("employee");
		String eid = e.getId();
		String cid = request.getParameter("cid");
		String content = request.getParameter("content");
		if(content!=""){
		com.kaishengit.entity.Contactnote cn = new com.kaishengit.entity.Contactnote();
		cn.setId(StringUtil.getId());
		cn.setContent(content);
		cn.setEmployeeid(eid);
		cn.setContactid(cid);
		
		new ContactnoteService().save(cn);
		com.kaishengit.entity.Contactnote contactnote = new ContactnoteService().findById(cn.getId());
		Map<String ,Object> map = new HashMap<String, Object>();
		map.put("e", e);
		map.put("cn", contactnote);
		Gson gson = new Gson();
		String json = gson.toJson(map);
		response.setContentType("application/json;charset=UTF-8");
		
		PrintWriter out = response.getWriter();
		out.println(json);
		out.flush();
		out.close();
		}
		
	}

}
